package edu.scau.core.Enum;

import io.swagger.v3.oas.annotations.media.Schema;

import java.util.HashMap;

public enum OrderStatus {
    @Schema(name = "0",description = "创建中")
    created("创建中",0),
    @Schema(name = "1",description = "已出库，未支付")
    Unpaid("已出库，未支付",1),
    @Schema(name = "2",description = "已支付")
    Paid("已支付",2),
    @Schema(name = "3",description = "缺货预定")
    //缺货已支付
    Backorder("缺货预定",3),
    @Schema(name = "4",description = "退单")
    Refunded("退单",4);
    private final String desc;
    private final int signal;
    OrderStatus(String desc,int signal) {
        this.desc = desc;
        this.signal=signal;
    }

    public String getDesc() {
        return desc;
    }

    public int getSignal(){
        return signal;
    }

    /**
     * 通过signal获取枚举常量
     * @param signal
     * @return
     */
    public static OrderStatus getBySignal(int signal) {
        for (OrderStatus status : OrderStatus.values()) {
            if (status.getSignal() == signal) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid signal: " + signal);
    }

}
